package collection.list;

import java.util.LinkedList;
import java.util.List;

/**
 * sublist()方法的演示
 */
public class SubListDemo {
    public static void main(String[] args) {
        List<Integer> list = new LinkedList<>();
        for (int i = 0; i <10 ; i++) {
            list.add(i*10);
        }
        System.out.println(list);//[0, 10, 20, 30, 40, 50, 60, 70, 80, 90]

        List<Integer> sub = list.subList(3,8);//获取3-7下表的子集
        System.out.println(sub);//[30, 40, 50, 60 ,70]

        //将子集扩大十倍
        for (int i = 0; i < sub.size() ; i++) {
            sub.set(i, sub.get(i)*10);
        }
        System.out.println("子集"+sub);
        System.out.println("原集"+list);
        System.out.println("++++++++++++++++++++++++++++++++++++++");

        list.set(3,1000);
        System.out.println(sub);//在原集合上进行操作,子集也会受影响

        list.remove(0);
        System.out.println(list);
      //  System.out.println(sub);
        //原集合长度修改后,子集将不能在进行任何操作,操作则发生异常,但可以重新获取子集









    }
}
